<?php
include_once ('include/conn.php');
$smarty->assign("Title", "查找");

if (($_POST['listsearch']==NULL) && ($_GET['listsearch']==NULL)){
$query = 'SELECT * FROM list LIMIT 0 ,30';
}else{
$listsearch = $_POST['listsearch'];
$query = 'SELECT * FROM `list` WHERE `name` LIKE \'%'.$listsearch.'%\' LIMIT 0, 30 '; 
};
    $result = mysql_query($query);
    ob_start();
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "[";
    foreach ($line as $col_value) {
       echo "'$col_value',";
    }echo "],";
    };
$liststr = ob_get_contents();
ob_end_clean();
$liststr = preg_replace ("[,\],]","],",$liststr);
$search = array ("'([\r\n])[\s]+'",                 // 去掉空白字符
                 "'&(quot|#34);'i",                 // 替换 HTML 实体
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i");    
$replace = array ("\\1",
                  "\"",
                  "&",
                  "<",
                  ">");
$liststr = preg_replace ($search, $replace, $liststr);
$liststr = substr($liststr,0,-1);
$smarty->assign("Liststr", $liststr);
$smarty->display("search.tpl");
?>

